package com.zzxx.controller;

import com.github.pagehelper.PageInfo;
import com.zzxx.domain.Orders;
import com.zzxx.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("orders")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @RequestMapping("findAll")
    public String findAll(Model model,
                          @RequestParam(name = "pageNum", required = true, defaultValue = "1") Integer pageNum,
                          @RequestParam(name = "pageSize", required = true, defaultValue = "4") Integer pageSize){
        List<Orders> list = ordersService.queryAll(pageNum, pageSize);
        PageInfo<Orders> pageInfo = new PageInfo<>(list);
        model.addAttribute("pageInfo", pageInfo);
        return "order-list";
    }

    @RequestMapping("findById")
    public String findById(Model model, @RequestParam(name = "oid", required = true) String oid){
        Orders order = ordersService.queryById(oid);
        model.addAttribute("order", order);
        return "order-detail";
    }
}
